package com.sunl.mall.trace.util;


/**
 * 生成线程内唯一id
 */
public class SerialNo {
    private static final ThreadLocal<String> SERIAL_NO_THREAD_LOCAL = new InheritableThreadLocal<>();

    public SerialNo() {
    }

    public static String init() {
        String id = TraceIdUtil.genId();
        SERIAL_NO_THREAD_LOCAL.set(id);
        return id;
    }

    public static String getSerialNo() {
        return SERIAL_NO_THREAD_LOCAL.get();
    }

    public static void clear() {
        SERIAL_NO_THREAD_LOCAL.remove();
    }
}
